from typing import Union, Optional, List

from fastapi import Query
from pydantic import BaseModel, validator

from app.schemas.common import DateTimeModelMixin
from app.schemas.user import SetImages, UserId, UserInfo


class CirclePostsSM(DateTimeModelMixin):
    uid: Union[int, None]
    content: str
    image: Union[list, str, None]

    class Config:
        orm_mode = True


class CircleLikesSM(DateTimeModelMixin):
    uid: Union[int, None]
    post_id: Union[int, None]

    class Config:
        orm_mode: True


class CircleCommentsSM(DateTimeModelMixin):
    uid: Union[int, None]
    post_id: Union[int, None]
    content: str

    class Config:
        orm_mode: True


class Item(BaseModel):
    id: int
    content: Union[str, None]
    images: Union[list, None]
    likes_count: int
    comments_count: int
    user: Union[UserInfo, None]

    @validator("user", pre=True, always=True)
    def default_datetime(cls, value):
        return value.__dict__


class CircleList(BaseModel):
    list: Union[List[Item], None]
    total: int = 0

    class Config:
        orm_mode = True
